package com.bawei.common.mvi

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.consumeAsFlow
import kotlinx.coroutines.launch


/**
 * 作者：Jason
 * 日期：2023/11/16
 * 描述：ViewModel基类
 */
abstract class BaseViewModel<I: BaseViewIntent>: ViewModel() {

    val channel: Channel<I> = Channel(Channel.UNLIMITED)

    init {
        //收集View层的意图
        viewModelScope.launch {
            channel.consumeAsFlow().collect{
                handIntent(it)
            }
        }
    }

    abstract fun handIntent(uiIntent: I)

}